//
//  HomePicForwardViewController.m
//  ioschishan
//
//  Created by 马田成 on 2017/8/1.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "HomePicForwardViewController.h"
#import "HomeLookNowViewController.h"
#import "HomeWaterNowViewController.h"


@interface HomePicForwardViewController ()<UITextViewDelegate,numDelegate>
{

    NSString *water_num;//水滴总数
    NSString *collar_num;//可领次数

}
@property (weak, nonatomic) IBOutlet UITextView *forwardFV;
@property (nonatomic, strong) UILabel *placeHolderLabel;
@property (weak, nonatomic) IBOutlet UIButton *waterBtn;
@property (weak, nonatomic) IBOutlet UIImageView *pic;
@property (weak, nonatomic) IBOutlet UILabel *nameLab;
@property (weak, nonatomic) IBOutlet UILabel *contentLab;

@end

@implementation HomePicForwardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    [self data];
    
    
    // Do any additional setup after loading the view from its nib.
}
- (void)data{

    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:_tieID forKey:@"circle_id"];

    
    [[MNetworkHandler sharedInstance]conURL:home_CircleforwardDynamicShow networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            NSMutableDictionary *dic = [returnData objectForKey:@"data"];
            self.nameLab.text = [dic objectForKey:@"user_name"];
            NSString *urlVpPic3 = manage(AP_HOST, [dic objectForKey:@"pic"]);
            
            [self.pic sd_setImageWithURL:[NSURL URLWithString:urlVpPic3] placeholderImage:[UIImage imageNamed:@""]];
            
            self.contentLab.text = [dic objectForKey:@"content"];

            
        }
        
        else {
            
        }
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
        
    }];

    
}
- (void)creationView{

    [self setTitle:@"转发"];
    
    UIButton *buttonAdd = [[UIButton alloc] init];
    
    buttonAdd.frame = CGRectMake(DEF_SCREEN_WIDTH - 50, 0, 40, 40);
    [buttonAdd setTitle:@"发布" forState:UIControlStateNormal];
    [buttonAdd setTitleColor:getColor(@"3A95FF") forState:UIControlStateNormal];
    
    [buttonAdd addTarget:self action:@selector(ReleaseClick) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem *rightItme = [[UIBarButtonItem alloc]initWithCustomView:buttonAdd];
    self.navigationItem.rightBarButtonItem = rightItme;

    self.placeHolderLabel = [[UILabel alloc] init];
    
    self.placeHolderLabel.numberOfLines = 0;
    self.placeHolderLabel.font = [UIFont systemFontOfSize:13];
    self.placeHolderLabel.textColor = getColor(@"9B9B9B");
    [self.placeHolderLabel sizeToFit];
    self.placeHolderLabel.text = @"转发动态，会同时评论原作者";
    self.forwardFV.delegate = self;

    [self.forwardFV addSubview:self.placeHolderLabel];
    
    [self.forwardFV setValue:self.placeHolderLabel forKey:@"_placeholderLabel"];
    

}

- (void)getWater:(NSString *)water andNum:(NSString *)num{
    
    if ([water length] == 0) {
        [self.waterBtn setTitle:@"+水滴" forState:UIControlStateNormal];
    }else {
        
        NSString *str1 = @"赏";
        NSString *str2 = [[[[[str1 stringByAppendingString:water] stringByAppendingString:@"水滴"] stringByAppendingString:@"/"] stringByAppendingString:num] stringByAppendingString:@"次"];
        
        [self.waterBtn setTitle:str2 forState:UIControlStateNormal];
        
    }
    water_num = water;
    collar_num = num;
    
    
    
}



//发布
- (void)ReleaseClick{

    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:_tieID forKey:@"circle_id"];
    [productParams setValue:water_num forKey:@"water_num"];
    [productParams setValue:collar_num forKey:@"collar_num"];
    [productParams setValue:self.forwardFV.text forKey:@"content"];
    
    [productParams setValue:@"1" forKey:@"type"];
    
    [[MNetworkHandler sharedInstance]conURL:home_CircleforwardDynamic networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
       
//            [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];
            [self.navigationController popToRootViewControllerAnimated:YES];
            
            
            
        }
        
        else {
            
        }
        
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
        
    }];

    
    

}
//水滴
- (IBAction)waterButtonClick:(UIButton *)sender {
    HomeWaterNowViewController *vc = [[HomeWaterNowViewController alloc] init];
    vc.delegate = self;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
